package com.lugu74.sipadan;

import java.util.List;

import weibo4andriod.Comment;
import weibo4andriod.Count;
import weibo4andriod.Status;
import weibo4andriod.Weibo;
import weibo4andriod.WeiboException;
import weibo4andriod.andriodexamples.OAuthConstant;
import weibo4andriod.http.AccessToken;
import weibo4andriod.org.json.JSONException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class TestActivity extends Activity {
    private String mToken;
	private String mTokenSecu;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        
		System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
    	System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
    	
    	
    	mToken = "fbcefae3d052c94dabf4a7e493f3923e";
    	mTokenSecu = "883b5ad6315384da889e27b4d8be0238";
    	

//		OAuthConstant.getInstance().setAccessToken(accessToken);
//		mWeiBo = OAuthConstant.getInstance().getWeibo();
//		mWeiBo.setToken(OAuthConstant.getInstance().getToken(), OAuthConstant.getInstance().getTokenSecret());
    	
    	mWeiBo = OAuthConstant.getInstance().getWeibo();      
    	mWeiBo.setToken(mToken, mTokenSecu);
    	
    	
		Button button1=  (Button) findViewById(R.id.button1);
		button1.setText("Timeline");
		button1.setOnClickListener(new Button.OnClickListener()
        {
            @Override
            public void onClick( View v )
            {
				try {
					//Friend TimeLine
					printStatus(mWeiBo.getFriendsTimeline());
					//Public TimeLine
					printStatus(mWeiBo.getPublicTimeline());
					//User TimeLine
					printStatus(mWeiBo.getUserTimeline());
					//Mentions TimeLine
					printStatus(mWeiBo.getMentions());
					//Comments TimeLine
					printComments(mWeiBo.getCommentsTimeline());
					//Comments by ME
					printComments(mWeiBo.getCommentsByMe());
					//Comments to ME
					printComments(mWeiBo.getCommentsToMe());
					//Comments by ID
					printComments(mWeiBo.getComments("1"));
					//Counts
					printCounts(mWeiBo.getCounts("1"));
					//Counts of unread
					printCounts(mWeiBo.getUnread());


				} catch (WeiboException e) {
					e.printStackTrace();
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
    					
            }


        } );
		
		Button button2=  (Button) findViewById(R.id.button2);
		button2.setText("MicroBlog");
		button2.setOnClickListener(new Button.OnClickListener()
        {
            @Override
            public void onClick( View v )
            {

            }

        } );		
		Button button3=  (Button) findViewById(R.id.button3);
		button3.setText("Update Status");
		button3.setOnClickListener(new Button.OnClickListener()
        {
            @Override
            public void onClick( View v )
            {
				try {
					printStatus(mWeiBo.updateStatus(":)"));

				} catch (WeiboException e) {
					e.printStackTrace();
				}
    					
            }

        } );			
	}
	protected void printCounts(Count unread) {
		Log.i(TAG,"Unread: "+unread.toString());
		
	}
	protected void printCounts(List<Count> commentsTimeline) {
		for (Count counts : commentsTimeline) {
			Log.i(TAG,"Followers: "+counts.getFollowers()+"  Mentions: "+counts.getMentions());
		}		
	}
	protected void printComments(List<Comment> commentsTimeline) {
		for (Comment comment : commentsTimeline) {
			Log.i(TAG,comment.getUser().getScreenName()+": "+comment.getText());
		}
	}
	protected void printStatus(Status updateStatus) {
		Log.i(TAG,updateStatus.getUser().getScreenName()+": "+updateStatus.getText());
		
	}
	void printStatus(List<Status> timeline) {
		for (Status status : timeline) {
			Log.i(TAG,status.getUser().getScreenName()+": "+status.getText());
		}
	}
	
	private static final String TAG = "TestActivity";
	private Weibo mWeiBo;

}
